const { formatTime_chinese } = require("../../../../common/util/util")

Page({
    data: {
        id: '',
        ava: '',
        name: '',
        number: '',
    },

    onLoad: function (opt) {
        this.setData({
            id: opt.id,
            ava: opt.ava,
            name: opt.name,
            number: opt.number
        })
        this.xInit()
    },

    xInit: function () {
        let that = this
        let id = that.data.id
        wx.cloud.callFunction({
            name: 'consulting_message',
            data: {
                action: "get_send_letter",
                from_openid: id
            }
        }).then(res => {
            let data = res.result
            console.log(data)
            for(var i in data){
                data[i].create_time = formatTime_chinese(new Date(data[i].create_time))
            }
            that.setData({
                list : data
            })
        })
    },

    xToDetail: function (e) {
        let params = e.currentTarget.dataset
        wx.navigateTo({
            url: '/subdter/pages/email/detail/index',
            success: function(res) {
                res.eventChannel.emit('acceptDataFromOpenerPage', params)
            }
        })
    }
})